spf.namespace('sitrack');

// application initialisation function
spf.sitrack.init = function() {
   
	var handleNo = function() {
		this.hide();
	};
   
   var handleYes = function() {
      
      // grab the target url from the confirmation dialog box and then clear it
      url = spf.sitrack.confirmBox.url;
      spf.sitrack.confirmBox.url = null;
      
      // send the user on their way...
      window.location = url;

   }; // handleYes
   
	// create a confirmation dialog box
	spf.sitrack.confirmBox = new YAHOO.widget.SimpleDialog("confirmBox", 
																			 { width: "300px",
																			   fixedcenter: true,
																			   visible: false,
																			   draggable: false,
																			   close: false,
																			   modal:true,
																			   text: "Are you sure?",
																			   icon: YAHOO.widget.SimpleDialog.ICON_HELP,
																			   constraintoviewport: true,
																			   buttons: [ { text:"Yes", handler:handleYes },
																						     { text:"No",  handler:handleNo } ]
																			 } );
	// set the header and
   spf.sitrack.confirmBox.setHeader("SiTrack");
	spf.sitrack.confirmBox.render("page");
   
   spf.sitrack.ticket_history = new YAHOO.widget.Dialog("ticket_history", { width:"650px",
                                                                            fixedcenter:false,
                                                                            close:true,
                                                                            visible:false,
                                                                            modal:true,
                                                                            autofillheight :"body"
                                                                            } );
   spf.sitrack.ticket_history.render();
   spf.sitrack.ticket_history.center();
   
}

// used on the /tickets/browse page to show/hide the additional search criteria
spf.sitrack.toggle_advanced_filter = function() {

   var obj = $('advanced');
   
   var visible = spf.toggle_display(obj);
   
   if( visible )
      $('toggle_advanced_filter').innerHTML = 'Less options...';
   else
      $('toggle_advanced_filter').innerHTML = 'More options...';
      
} // toggle_advanced_filter


// replacement for the standard confirm() function that uses a nice YUI dialog box and then
// 
spf.sitrack.confirm = function(url) {
	
   spf.sitrack.confirmBox.url = spf.sitrack.base_url + url;
   
   spf.sitrack.confirmBox.show();
   
} // confirm

YAHOO.util.Event.addListener(window, "load", spf.sitrack.init);
